package com.yinhe.music.yhmusic.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.cache.CacheManager;
import com.yinhe.music.yhmusic.model.SongMenuList;

import java.util.List;

/**
 * Created by hasee on 2017/8/15.
 */

public class RecommendMenuAdapter extends BaseQuickAdapter<SongMenuList, BaseViewHolder> {
    private static final int MAX = 10000;

    public RecommendMenuAdapter(@Nullable List<SongMenuList> data) {
        super(CacheManager.getInstance().getTypeLangId() != 1
                ? R.layout.recommend_menu_item
                : R.layout.recommend_twist_item, data);
    }

    public RecommendMenuAdapter() {
//        super(CacheManager.getInstance().getTypeLangId() != 1
//                ? R.layout.recommend_menu_item
//                : R.layout.recommend_twist_item);
        super(R.layout.recommend_menu_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, SongMenuList item) {
        if (CacheManager.getInstance().getTypeLangId() != 1) {
            helper.setText(R.id.song_menu_name, item.getSongMenuName());
            TextView count = helper.getView(R.id.song_menu_play_num);
            if (count != null) {
                if (item.getPlay() < MAX) {
                    helper.setText(R.id.song_menu_play_num, String.valueOf(item.getPlay()));
                } else {
                    helper.setText(R.id.song_menu_play_num, item.getPlay() / MAX + "万");
                }
            }

            helper.setGone(R.id.anchor, false);
            ImageView image = helper.getView(R.id.song_menu_img);
            GlideHelper.setImageResource(image, item.getImage(), R.drawable.default_cover);
        } else {
            helper.setText(R.id.song_menu_name, item.getSongMenuName());
            ImageView image = helper.getView(R.id.song_menu_img);
            GlideHelper.setImageResource(image, item.getImage(), R.drawable.default_cover);
        }
    }
}
